﻿namespace WordCloudClient.ViewModels.CommonVM
{
    public abstract class WinBaseVM : BindableBase, IDialogAware
    {
        public INIFile INIFileLauncher = new(".\\Data\\Config.ini");
        public readonly ISystemService _systemService;
        public readonly WinEditHelper _winEditHelper;

        public DelegateCommand ExecuteSaveDelegateCommand { get; set; }
        public DelegateCommand ExecuteCancelDelegateCommand { get; set; }
        public DelegateCommand<object> ExecuteSelectFileDelegateCommand { get; private set; }

        public WinBaseVM(SystemService systemService, WinEditHelper winEditHelper)
        {
            _systemService = systemService;
            _winEditHelper = winEditHelper;
            ExecuteSaveDelegateCommand = new DelegateCommand(ExecuteSave);
            ExecuteCancelDelegateCommand = new DelegateCommand(ExecuteCancel);
            ExecuteSelectFileDelegateCommand = new DelegateCommand<object>(ExecuteSelectFile);
        }


        public virtual void ExecuteSave()
        {

        }

        public virtual void ExecuteCancel()
        {
            RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
        }

        public virtual void ExecuteSelectFile(object o)
        {

        }
        public virtual void RaiseRequestClose(IDialogResult dialogResult)
        {
            RequestClose?.Invoke(dialogResult);
        }
        #region IDialogAware实现
        public string Title { get; set; } = string.Empty;

        public event Action<IDialogResult>? RequestClose;
        /// <summary>
        /// 是否允许关闭当前窗口
        /// </summary>
        /// <returns></returns>
        public bool CanCloseDialog()
        {
            return true;
        }
        /// <summary>
        /// 关闭对话框时触发
        /// </summary>
        public void OnDialogClosed()
        {

        }
        /// <summary>
        /// 打开之前传递参数
        /// </summary>
        /// <param name="parameters">接收的参数</param>
        /// <exception cref="NotImplementedException"></exception>
        public abstract void OnDialogOpened(IDialogParameters parameters);
        #endregion
    }
}
